package com.justonetech.translation.domain.base;

import com.justonetech.system.domain.SysCodeDetail;
import com.justonetech.translation.domain.Bill;
import com.justonetech.translation.domain.BillDetail;
import com.justonetech.translation.domain.Project;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;


/**
 * This is an object that contains data related to the bill table.
 * Do not modify this class because it will be overwritten if the configuration file
 * related to this class is modified.
 * TableComment : 账单
 * SyncTemplatepatterns : list\w*
 * SyncDao : false
 * TableName : 账单
 * SyncBoolean : get
 * SyncJsp : true
 * Treeable : false
 * Projectable : true
 *
 * @hibernate.class
 *  table="bill"
 */
@JsonIgnoreProperties(value={"hibernateLazyInitializer"})
public abstract class BaseBill  implements Serializable{

	public static String REF = "Bill";
	public static String PROP_TYPE = "type";
	public static String PROP_AMOUNT = "amount";
	public static String PROP_TASK = "task";
	public static String PROP_MODIFIER = "modifier";
	public static String PROP_REMARK = "remark";
	public static String PROP_HANDLER = "handler";
	public static String PROP_ACCOUT_DATE = "accoutDate";
	public static String PROP_PROJECT = "project";
	public static String PROP_ID = "id";


	// constructors
	public BaseBill () {
		initialize();
	}

	/**
	 * Constructor for primary key
	 */
	public BaseBill (Long id) {
		this.setId(id);
		initialize();
	}

	protected void initialize () {}



	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private Long id;

	// fields
    /*金额*/
    /*金额(元)*/
	private Double amount;
	
    /*帐单类型*/
    /*帐单类型*/
	private SysCodeDetail billType;
	
    /*帐单生成日期*/
    /*帐单生成日期*/
	private java.sql.Date accoutDate;
	
    /*经手人*/
    /*经手人*/
	private String handler;
	
    /*修改人*/
    /*修改人*/
	private String modifier;
	
    /*备注*/
    /*备注*/
	private String remark;

	// many to one
	private Project project;

	private com.justonetech.translation.domain.Task task;

    @JsonIgnore
    private Set<BillDetail> billDetails;

	/**
	 * Return the unique identifier of this class
     * @hibernate.id
     *  generator-class="com.justonetech.core.orm.hibernate.LongIdGenerator"
     *  column="ID"
     */
	public Long getId () {
		return id;
	}

	/**
	 * Set the unique identifier of this class
	 * @param id the new ID
	 * @deprecated
	 */
	public void setId (Long id) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}




	/**
	 * Return the value associated with the column: AMOUNT
	 */
	public Double getAmount () {
		return amount;
	}

	/**
	 * Set the value related to the column: AMOUNT
	 * @param amount the AMOUNT value
	 */
	public void setAmount (Double amount) {
		this.amount = amount;
	}


	/**
	 * Return the value associated with the column: BILL_TYPE
	 */
	public SysCodeDetail getBillType () {
		return billType;
	}

	/**
	 * Set the value related to the column: BILL_TYPE
	 * @param billType the BILL_TYPE value
	 */
	public void setBillType (SysCodeDetail billType) {
		this.billType = billType;
	}


	/**
	 * Return the value associated with the column: ACCOUT_DATE
	 */
	public java.sql.Date getAccoutDate () {
		return accoutDate;
	}

	/**
	 * Set the value related to the column: ACCOUT_DATE
	 * @param accoutDate the ACCOUT_DATE value
	 */
	public void setAccoutDate (java.sql.Date accoutDate) {
		this.accoutDate = accoutDate;
	}


	/**
	 * Return the value associated with the column: HANDLER
	 */
	public String getHandler () {
		return handler;
	}

	/**
	 * Set the value related to the column: HANDLER
	 * @param handler the HANDLER value
	 */
	public void setHandler (String handler) {
		this.handler = handler;
	}


	/**
	 * Return the value associated with the column: MODIFIER
	 */
	public String getModifier () {
		return modifier;
	}

	/**
	 * Set the value related to the column: MODIFIER
	 * @param modifier the MODIFIER value
	 */
	public void setModifier (String modifier) {
		this.modifier = modifier;
	}


	/**
	 * Return the value associated with the column: REMARK
	 */
	public String getRemark () {
		return remark;
	}

	/**
	 * Set the value related to the column: REMARK
	 * @param remark the REMARK value
	 */
	public void setRemark (String remark) {
		this.remark = remark;
	}


	/**
	 * Return the value associated with the column: PROJECT_ID
	 */
	public Project getProject () {
		return project;
	}

	/**
	 * Set the value related to the column: PROJECT_ID
	 * @param project the PROJECT_ID value
	 */
	public void setProject (Project project) {
		this.project = project;
	}


	/**
	 * Return the value associated with the column: TASK_ID
	 */
	public com.justonetech.translation.domain.Task getTask () {
		return task;
	}

	/**
	 * Set the value related to the column: TASK_ID
	 * @param task the TASK_ID value
	 */
	public void setTask (com.justonetech.translation.domain.Task task) {
		this.task = task;
	}

    @JsonIgnore
    public Set<BillDetail> getBillDetails() {
        if(billDetails == null) {
            billDetails = new LinkedHashSet<BillDetail>();
        }

        return billDetails;
    }

    public void setBillDetails(Set<BillDetail> billDetails) {
        this.billDetails = billDetails;
    }

    public void addToBillDetails (BillDetail bean) {
        if (null == getBillDetails()) setBillDetails(new LinkedHashSet<BillDetail>());
        this.billDetails.add(bean);
    }

	public boolean equals (Object obj) {
		if (null == obj) return false;
		if (!(obj instanceof Bill)) return false;
		else {
			Bill bill = (Bill) obj;
			if (null == this.getId() || null == bill.getId()) return false;
			else return (this.getId().equals(bill.getId()));
		}
	}

	public int hashCode () {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getId()) return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}


	public String toString () {
		ToStringBuilder builder = new ToStringBuilder(this);
		builder.append(id);
		builder.append(amount);
		builder.append(billType);
		builder.append(accoutDate);
		builder.append(handler);
		builder.append(modifier);
		builder.append(remark);
		return builder.toString();
	}


}